<?php
/*
 *      _______ _     _       _     _____ __  __ ______
 *     |__   __| |   (_)     | |   / ____|  \/  |  ____|
 *        | |  | |__  _ _ __ | | _| |    | \  / | |__
 *        | |  | '_ \| | '_ \| |/ / |    | |\/| |  __|
 *        | |  | | | | | | | |   <| |____| |  | | |
 *        |_|  |_| |_|_|_| |_|_|\_\\_____|_|  |_|_|
 */
/*
 *     _________  ___  ___  ___  ________   ___  __    ________  _____ ______   ________
 *    |\___   ___\\  \|\  \|\  \|\   ___  \|\  \|\  \ |\   ____\|\   _ \  _   \|\  _____\
 *    \|___ \  \_\ \  \\\  \ \  \ \  \\ \  \ \  \/  /|\ \  \___|\ \  \\\__\ \  \ \  \__/
 *         \ \  \ \ \   __  \ \  \ \  \\ \  \ \   ___  \ \  \    \ \  \\|__| \  \ \   __\
 *          \ \  \ \ \  \ \  \ \  \ \  \\ \  \ \  \\ \  \ \  \____\ \  \    \ \  \ \  \_|
 *           \ \__\ \ \__\ \__\ \__\ \__\\ \__\ \__\\ \__\ \_______\ \__\    \ \__\ \__\
 *            \|__|  \|__|\|__|\|__|\|__| \|__|\|__| \|__|\|_______|\|__|     \|__|\|__|
 */
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace Portal\Controller;
use Common\Controller\HomebaseController;
/**
 * 首页
 */
class IndexController extends HomebaseController {
	
    //首页 小夏是老猫除外最帅的男人了
	public function index() {
        $partners=M('partners')->select();
        $projects=M('projects')
            ->alias("a")
            ->field('a.*,b.name')
            ->join("__PROJECTS_CAT__ b ON a.c_id = b.id")
            ->select();
        $cat=M('projects_cat')->select();
        foreach ($cat as $val){
            $cat_name[]=$val['name'];
        }
        $cat_name=implode(" ",$cat_name);
        $this->assign('partners',$partners);
        $this->assign('projects',$projects);
        $this->assign('cat',$cat);
        $this->assign('cat_name',$cat_name);
    	$this->display(":index");
    }
    public function about_us(){
	    $this->display(":about_us");
    }
    public function services(){
        $result=M('partners')->select();
        $this->assign('result',$result);
        $this->display(":services");
    }
    public function carrers(){
        $result=M('center')
            ->alias("a")
            ->field('a.*,b.name')
            ->join("__CENTER_CAT__ b ON a.c_id = b.id")
            ->select();
        $cat=M('center_cat')->select();
        $this->assign('result',$result);
        $this->assign('cat',$cat);
        $this->display(":carrers");
    }
    public function contact(){
        $this->display(":contact");
    }
    public function contact_post(){
        //dump($_POST);die;
        $data['name']=I('post.name');
//        $data['website']=I('post.website');
        $data['phone']=I('post.phone');
        $data['email']=I('post.email');
        $data['message']=I('post.message');
        $data['createtime']=date("Y-m-d H:i:s");
        !empty($data['name'])?:$this->error('请填写姓名');
//        !empty($data['website'])?:$this->error('请填写网站');
        !empty($data['email'])?:$this->error('请填写邮箱');
        !empty($data['phone'])?:$this->error('请填写电话');
        !empty($data['message'])?:$this->error('请填写内容');
        if(!preg_match("/^\d{11}$/",$data['phone'])){
            $this->error('电话号不符合要求!');
        }
        if(!preg_match("/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/",$data['email'])){
            $this->error('邮箱不符合要求!');
        }
        if(M('guestbook')->add($data)){
            $this->success('发送成功','','3');
        }else{
            $this->error('发送失败');
        }
    }

}


